package com.whisperarts.financer.app.model.rcp;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import com.whisperarts.financer.dao.AccountsDAO;
import com.whisperarts.financer.model.account.Account;
import com.whisperarts.financer.model.account.AccountsCategory;


public class AccountsContentProvider implements ITreeContentProvider {
	private AccountsMockModel model;

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
//		this.model = (AccountsMockModel) newInput;
	}

	@Override
	public Object[] getElements(Object inputElement) {
		return AccountsDAO.getAccountsCategories();
	}

	@Override
	public Object[] getChildren(Object parentElement) {
		if (parentElement instanceof AccountsCategory) {
			AccountsCategory category = (AccountsCategory) parentElement;
			return category.getAccounts().toArray();
		} else if (parentElement instanceof Account) {
			Account account = (Account) parentElement;
			return account.getAccountInfo().toArray();
		} else {
			return null;
		}
			
	}

	@Override
	public Object getParent(Object element) {
		return null;
	}

	@Override
	public boolean hasChildren(Object element) {		
		if (element instanceof AccountsCategory) {
			if (((AccountsCategory) element).getAccounts().size() == 0)
				return false;
		} else if (!(element instanceof Account)) {
			return false;
		}
		return true;
	}
}
